﻿using Bll;
using Help;
using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;

namespace Myproject.BSM.Ashx
{
    /// <summary>
    /// load 的摘要说明
    /// </summary>
    public class load : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string logName = context.Request.Params["loginname"];
            string loginpwd = context.Request.Params["loginpwd"];
            if (!new AdminBLL().ExistsByAdminName(logName))
            {
                context.Response.Write(ReturnJsonHelp.OutHandlerJson(false, "账号不存在"));
            }
            else
            {
                DataRow dr = new AdminBLL().GetList(" AdminName='" + logName + "' ").Tables[0].Rows[0];
                if (dr["AdminPwd"].ToString() != loginpwd)
                {
                    context.Response.Write(ReturnJsonHelp.OutHandlerJson(false, "密码错误"));
                }
                else
                {
                    cookieHelp.ClearCookies();
                    cookieHelp.SetCookies(dr["AdminId"].ToString(), dr["AdminName"].ToString());

                    try
                    {
                        AdminModel model = new AdminBLL().GetModel(int.Parse(dr["AdminId"].ToString()));
                        model.LastLoadTime = model.ThisLoadTime;
                        model.ThisLoadTime = DateTime.Now;
                        new AdminBLL().Update(model);
                    }
                    catch (Exception)
                    {
                    }
                    context.Response.Write(ReturnJsonHelp.OutHandlerJson(true, "登录成功"));
                }
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}